<template>
    <div>
        <el-dialog
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        title="创建投诉工单"
        :center="true"
        :visible.sync="isshowwindow"
        @close="closew"
        @closed="restform"
        width="690px">
            <el-form  label-width="100px">
                <el-form-item label="订单id">
                    {{ tousuid }}
                </el-form-item>
                <el-form-item :required='true' label="投诉来源">
                    <el-select v-model="form.source" placeholder="请选择投诉来源">
                        <el-option v-for="(item,index) in tsfrom" :key="index" :label="item.label" :value="item.value"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item :required='true' label="投诉类型">
                    <el-select v-model="form.type_id" placeholder="请选择投诉类型">
                        <el-option v-for="(item,index) in taglist" :key="index" :label="item.title" :value="item.id"></el-option>
                    </el-select>
                    <el-button @click="openchangetag" style="margin-left: 20px;" type="primary" round plain>管理类型</el-button>
                </el-form-item>
                <el-form-item :required='true' label="处理优先级">
                    <el-select v-model="form.priority" placeholder="请选择处理优先级">
                        <el-option v-for="(item,index) in firstsort" :key="index" :label="item.label" :value="item.value"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item :required='true' label="投诉内容">
                    <el-input v-model="form.content" type="textarea" ></el-input>
                </el-form-item>
                <el-form-item label="处理要求">
                    <el-input v-model="form.requirement" type="textarea" ></el-input>
                </el-form-item>
                <el-form-item :required='true' label="截止时间">
                    <el-date-picker
                    value-format="yyyy-MM-dd HH:mm:ss"
                    v-model="form.overdue_at"
                    type="datetime"
                    placeholder="选择日期时间">
                    </el-date-picker>
                </el-form-item>
            </el-form>
            <div style="text-align: center;">
                <el-button type="danger" round @click="creategd">确认创建</el-button>
            </div>
        </el-dialog>
        <el-dialog
            :close-on-click-modal="false"
            :close-on-press-escape="false"
            title="管理任务类型"
            :visible.sync="isshowtag"
            width="500px">
            <div class="t_tag_box">
                <div v-for="(item,index) in taglist" :key="index" class="t_tag">
                    {{ item.title }}
                    <i @click="edittag(item.id,item.title)" style="margin-left: 5px;cursor: pointer;" class="el-icon-edit"></i>
                </div>
            </div>
            <div>
                <el-input style="width: 350px;margin-right: 10px;" v-model="addtagname" placeholder="请输入类型"></el-input>
                <el-button type="primary" @click="addtag" round>添加</el-button>
            </div>
            <div style="text-align: center;margin-top: 15px;">
                <el-button type="danger" round @click="closetag">关闭</el-button>
            </div>
        </el-dialog>
    </div>
    
</template>
<script>
import axios from "axios"
export default {
    data() {
        return {
            //投诉来源
            tsfrom:[
                {
                    value:1,
                    label:'运营商投诉'
                },
                {
                    value:2,
                    label:'工商局投诉'
                },
                {
                    value:3,
                    label:'平台工单投诉'
                },
                {
                    value:4,
                    label:'电话投诉'
                },
                {
                    value:5,
                    label:'其他投诉'
                },
            ],
            //处理优先级
            firstsort:[
                {
                    value:3,
                    label:'最高'
                },
                {
                    value:2,
                    label:'较高'
                },
                {
                    value:1,
                    label:'普通'
                },
                {
                    value:0,
                    label:'较低'
                },
            ],
            //表单
            form:{
                order_id:'',
                source:'',
                type_id:'',
                priority:'',
                content:'',
                requirement:'',
                overdue_at:''
            },
            //标签弹窗
            isshowtag:false,
            //类型列表
            taglist:[],
            //添加tag名
            addtagname:'',
            //修改的tagid
            changetagid:'',
            //点击一次
            isclick:false
        }
    },
    props:['isshowwindow','tousuid'],
    created() {
        
    },
    mounted() {
        //获取标签列表
        this.gettaglist()
    },
    methods: {
        //关闭
        closew(){
            this.$emit('creategdhide')
        },
        //确认创建
        creategd(){
           if(!this.isclick){

            this.isclick = true

            if(this.form.source==''){
                this.$message.error('请选择投诉来源');
                this.isclick = false
                return
            }else if(this.form.type_id==''){
                
                this.$message.error('请选择投诉类型')
                this.isclick = false;
                return
            }else if(this.form.priority.toString()==''){
                
                this.$message.error('请选择处理优先级');
                this.isclick = false
                return
            }else if(this.form.content==''){
                this.$message.error('请填写投诉内容');
                this.isclick = false
                return
            }else if(this.form.overdue_at==''){
                this.$message.error('请选择时间');
                this.isclick = false
                return
            }

            this.form.order_id = this.tousuid
            console.log('===---')
            console.log(this.form)
            axios.post('/api/plan-market/admin/complaint/job/add',this.form)
            .then(response => {
                if (response.data.msg.code == 0) {
                    console.log(response)
                    this.$message({
                        message: '添加成功',
                        type: 'success'
                    });
                    this.$emit('creategd')
                    //修改数量
                    axios.post('/api/gth/admin/complaint/job/count')
                    .then(response => {
                        if (response.data.msg.code == 0) {
                            this.resetSetItem('watchStorage', response.data.data.total);
                            this.isclick = false
                        } else {
                            this.$message.error(response.data.msg.info);
                        }
                    })
                    
                } else {
                    this.$message.error(response.data.msg.info);
                    this.isclick = false
                }
            })
           }
            
            
        },
        //完全关闭重置表单
        restform(){
            this.form.order_id=''
            this.form.source=''
            this.form.type_id=''
            this.form.priority=''
            this.form.content=''
            this.form.requirement=''
            this.form.overdue_at=''
        },
        //获取标签列表
        gettaglist(){
            axios.get('/api/gth/admin/complaint/job/type/list',)
                .then(response => {
                    if (response.data.msg.code == 0) {
                        console.log('获取标签列表')
                        console.log(response)
                        this.taglist = response.data.data
                        
                    } else {
                        this.$message.error(response.data.msg.info);
                    }
                })
        },
        
        //关闭标签弹窗
        closetag(){
            this.isshowtag = false
        },
        //打开管理类型
        openchangetag(){
            this.isshowtag = true
        },
        //修改标签
        edittag(id,title){
            this.changetagid = id
            this.addtagname = title
            
        },
        //添加标签
        addtag(){
            if(this.addtagname==''){
                this.$message.error('请输入名称');
            }else{
                if(this.changetagid==''){
                    //新增
                    axios.post('/api/plan-market/admin/complaint/job/type/add',{
                        title:this.addtagname
                    } )
                    .then(response => {
                        if (response.data.msg.code == 0) {
                            console.log(response)
                            this.$message({
                                message: '添加成功',
                                type: 'success'
                            });
                            this.addtagname=''
                            //获取标签列表
                            this.gettaglist()
                        } else {
                            this.$message.error(response.data.msg.info);
                        }
                    })
                }else{
                    //编辑
                    axios.post('/api/plan-market/admin/complaint/job/type/edit',{
                        id:this.changetagid,
                        title:this.addtagname
                    } )
                    .then(response => {
                        if (response.data.msg.code == 0) {
                            console.log(response)
                            this.$message({
                                message: '编辑成功',
                                type: 'success'
                            });
                            this.addtagname=''
                            this.changetagid=''
                            //获取标签列表
                            this.gettaglist()
                        } else {
                            this.$message.error(response.data.msg.info);
                        }
                    })
                }
                
            }
        }
    }
}
</script>
<style  scoped>
.t_tag_box{
    display: flex;
    flex-wrap:wrap;
}
.t_tag{
    color: #037FFF;
    background-color: #F5FBFF;
    border: 1px solid #037FFF;
    border-radius: 30px;
    padding: 7px 10px;
    margin-right: 10px;
    margin-bottom: 15px;
}
</style>